<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 幕小铺科技（大连）有限公司 [ http://www.XXX.com ]
// +----------------------------------------------------------------------
// | 2020/03/14 jason wang
// +----------------------------------------------------------------------
namespace app\erp\logic;
use think\facade\Hook;
use think\DB;
use util\Tree;
use think\facade\Debug;
use think\facade\Cache;
class GoodsSpecificationslogic{

    /**
     * 根据 goodsid 商品参数
     * @param  int    $user_id   操作用户ID
     * @author jason
     * @return mixed
     */
    public function getListByGoodsid($goods_id){
        DB::startTrans();//启动事务
        //try{
            /********行为参数赋值（*）********/
            $params = [
				'goods_id' 	            => $goods_id,
            ];
            /********行为参数赋值（*）********/
     
            /********前置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'before');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1002, $hook_rel['message']);//前置错误 -1002
            }
            /********前置行为********/

            /********业务逻辑********/
            $map =[];
            $map['goods_id'] = $goods_id;
            $list = model('erp/ErpGoodsSpecifications') -> where($map) -> select();
            $rel_list = [];
            foreach ($list as $key => $value) {
                //dump($value->get_erp_goods_imgs->img_url)
                //查询所有规格下得参数集合
                $map = [];
                $map['specifications_id'] = $value['specifications_id'];
                $map['goods_id'] = $goods_id;
                $list = model('erp/ErpGoodsSpecificationsAttribute') -> where($map) -> select();
                if($list) $list = $list -> toArray();
                //dump($list);
                $rel_list[] = [
                    'specifications_id'         => $value -> specifications_id,
                    'specifications_title'      => $value -> specifications_title,
                    'specifications_attribute'  => $list,
                ];
                
            }
            //dump($rel_list);
            /********业务逻辑********/
			
            /********后置行为********/
            $hook_rel = logic_hook($action = __FUNCTION__, $params, 'after');
            if($hook_rel['code'] < 0){
                DB::rollback();
                return array_out(-1003, $hook_rel['message']);//后置错误 -1003
            }
            /********后置行为********/

            /********逻辑返回********/
			DB::commit();
            return array_out(200, 'success', $rel_list);
            /********逻辑返回********/
			
        /* } catch (\Exception $e) {
			DB::rollback();
            return array_out(-9999, $e -> getMessage());//异常错误 -9999
        } */
    }
	
}